﻿@inherits EditOperationDialogBase<UserDto, int,UserCenterResource>
@if (_editModel != null)
{
    <Form Loading="@_isLoading"
          Model="@_editModel"
          LabelCol="new ColLayoutParam { Span = 8 }"
          WrapperCol="new ColLayoutParam { Span = 16 }"
          OnFinish="OnFormFinish"
          Context="model">
        <Row Gutter="24">
            <GridCol Span="11">
                <Divider Orientation="left" Style="font-weight:bold">@localizer["BasicInformation"]</Divider>
                <FormItem Label="@localizer[UserCenterResource.Avatar]">
                    @if (DrawerInputType.Edit.Equals(this.Options.Type) || DrawerInputType.Add.Equals(this.Options.Type))
                    {

                        <Tooltip Placement="Placement.LeftTop" Title="@localizer[UserCenterResource.ClickUpdateAvatar]">
                            <a @onclick="_ => OnAvatarClick(model)">
                                <Avatar Src="@model.Avatar" />
                            </a>
                        </Tooltip>

                    }
                    else if (DrawerInputType.Select.Equals(this.Options.Type))
                    {
                        <Avatar Src="@model.Avatar" />
                    }
                </FormItem>
                <FormItem Label="@localizer["Dept"]">
                    @if (deptDatas != null && deptDatas.Count > 0)
                    {
                        <TreeSelect TItem="DeptDto"
                                    Style="width:100%;"
                                    DataSource="deptDatas"
                        @bind-Value="@deptId"
                                    Placeholder="@localizer[SharedLocalResource.PleaseSelect]"
                                    AllowClear
                                    TitleExpression="node => node.DataItem.Name"
                                    KeyExpression="node => node.DataItem.Id.ToString()"
                                    ChildrenExpression="node => node.DataItem.Children?.ToList()"
                                    IsLeafExpression="node => node.DataItem.Children == null"
                                    TreeDefaultExpandAll>
                        </TreeSelect>
                    }
                </FormItem>
                <FormItem Label="@localizer["Position"]">
                    <Select DataSource="@positions"
                    @bind-Value="@model.PositionId"
                            ValueName="@nameof(PositionDto.Id)"
                            LabelName="@nameof(PositionDto.Name)"
                            OnSelectedItemChanged="OnSelectedItemChangedHandler"
                            TItem="PositionDto"
                            TItemValue="int?"
                            AllowClear>
                    </Select>
                </FormItem>
                <FormItem Label="@localizer["UserName"]">
                    <Input @bind-Value="@model.UserName" />
                </FormItem>
                <FormItem Label="@localizer["Password"]">
                    <Input Type="password" @bind-Value="@model.Password" />
                </FormItem>
                <FormItem Label="@localizer["NickName"]">
                    <Input @bind-Value="@model.NickName" />
                </FormItem>
                <FormItem Label="@localizer["Gender"]">
                    <RadioGroup @bind-Value="@(model.Gender)">
                        @foreach (var gitem in EnumHelper.EnumToDictionary<Gender>())
                        {
                            <Radio Value="@(gitem.Key)">@localizer[gitem.Value]</Radio>
                        }
                    </RadioGroup>
                </FormItem>
                <FormItem Label="@localizer["IsLocked"]">
                    <Switch @bind-Value="@model.IsLocked"></Switch>
                </FormItem>
            </GridCol>
            <GridCol Offset="2" Span="11">
                <Divider Orientation="left" Style="font-weight:bold">@localizer["ContactInformation"]</Divider>
                <FormItem Label="@localizer["PhoneNumber"]">
                    <Input @bind-Value="@model.PhoneNumber" />
                </FormItem>
                <FormItem Label="@localizer["PhoneNumberConfirmed"]">
                    <Switch @bind-Value="@model.PhoneNumberConfirmed"></Switch>
                </FormItem>
                <FormItem Label="@localizer["Email"]">
                    <Input @bind-Value="@model.Email" />
                </FormItem>
                <FormItem Label="@localizer["EmailConfirmed"]">
                    <Switch @bind-Value="@model.EmailConfirmed"></Switch>
                </FormItem>
                <FormItem Label="@localizer["QQ"]">
                    <Input @bind-Value="@model.UserExtension.QQ" />
                </FormItem>
                <FormItem Label="@localizer["WeChat"]">
                    <Input @bind-Value="@model.UserExtension.WeChat" />
                </FormItem>
            </GridCol>
        </Row>
        <Row Gutter="24">
            <GridCol Offset="6" Span="18">
                <FormItem WrapperCol="new ColLayoutParam { Offset = 4, Span = 20 }">
                    <Space>
                        @if (!DrawerInputType.Select.Equals(this.Options.Type))
                        {
                            <SpaceItem>
                                <Button Type="@ButtonType.Primary" HtmlType="submit">
                                    @localizer[SharedLocalResource.Save]
                                </Button>
                            </SpaceItem>
                        }
                        <SpaceItem>
                            <Button OnClick="OnFormCancel">
                                @localizer[SharedLocalResource.Cancel]
                            </Button>
                        </SpaceItem>
                    </Space>
                </FormItem>
            </GridCol>
        </Row>
    </Form>
}